*County Crosswalks for 1850

clear
insheet using "Eckert_countycrosswalk.csv"

keep if year==1850
save "EGLP_1850.dta", replace

*Obtain county characteristics, based on full count
do countycharacteristics_1850.do

*Obtain other 1850 county characteristics from NHGIS
do nhgisctycharfile.do

clear

*Merge datasets
use "ctychars_1850.dta"

*Merge 1850 characteristics from NHGIS
merge 1:1 cty_fips1850 using "ctypop1850_1990.dta"
rename _merge merge1850pop

keep if merge1850pop==3

rename cty_fips1850 cty_fips

*Merge to normal and asylum counties
merge 1:1 cty_fips using "justnormasylum.dta"
rename _merge mergenormasylum

keep if mergenormasylum==3

gen pcturbanover2500 = urbanover2500pop/pop1850
gen pctpopcities25000pop = popcities25000pop/pop1850
gen pctnonwhitefreepop = nonwhitefreepop/pop1850
gen pctnonwhiteslavepop = nonwhiteslavepop/pop1850

gen lnpop1850 = ln(pop1850)

*Table A1: 1850 characteristics

#delimit ;
local vars pcturbanover2500 pctpopcities25000pop  pctnonwhitefreepop pctnonwhiteslavepop pop1850 pctfarmer realproppc;
#delimit cr
foreach x of local vars{
#delimit ;
tabout hasnormalschool if hasnormalorasylum==1 using "sumstats.xls",
append c(mean `x' sd `x') npos(row) f(2)  layout(row) sum show(none);

reghdfe `x' hasnormalschool if hasnormalorasylum==1, absorb(statefip) cluster(statefip);
outreg2 using "balanceregs.xls", append excel dec(2);
};

#delimit cr
reghdfe pcturbanover2500 hasnormalschool if hasnormalorasylum==1, absorb(statefip) cluster(statefip)
gen samp = e(sample)==1

tab hasnormalschool if samp==1
#delimit cr
pca pcturbanover2500 pctpopcities25000pop  pctnonwhitefreepop pctnonwhiteslavepop pop1850 pctfarmer realproppc if hasnormalorasylum==1 & samp==1

predict pc1 pc2 pc3 pc4 pc5 pc6 pc7, score

#delimit cr
reghdfe pc1 hasnormalschool if hasnormalorasylum==1, absorb(statefip) cluster(statefip)
outreg2 using "balanceregs.xls", append excel dec(2)

reghdfe lnpop1850 hasnormalschool if hasnormalorasylum==1, absorb(statefip) cluster(statefip)

*Text statistic, Appendix A: Population without outlier of NY county
reghdfe pop1850 hasnormalschool if hasnormalorasylum==1, absorb(statefip) cluster(statefip)

su pop1850 if e(sample)==1, d
tab cty_fips if pop1850==r(max)
reghdfe pop1850 hasnormalschool if hasnormalorasylum==1 & cty_fips~=36061, absorb(statefip) cluster(statefip)
su pop1850 if hasnormalorasylum==1 & hasnormalschool==0 & cty_fips~=36061
